package com.book.bridge.function;

import com.book.pojo.UserInfo;
import com.book.repo.UserRepository;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author oyz
 * @version 1.0.4
 * @description:抽象类,作为中间类过渡
 * @date 2023/10/31 22:13
 */
public abstract class AbstractRegisterLoginFunc implements RegisterLoginFunctionInterface {


    protected String commonLogin(String account, String password, UserRepository repository){
        UserInfo userInfo = repository.findByUserNameAndUserPassword(account, password);
        if(null == userInfo){
            return "account or password error!";
        }
        return "Login successfully";
    }


    protected String commonRegister(UserInfo info,UserRepository repository){
        if(checkUserExists(info.getUserName())){
            throw new RuntimeException("account already exist!");
        }
        info.setCreateDate(new Date());
        repository.save(info);
        return "register successfully";
    }

    protected boolean commoncheckUserExists(String userName,UserRepository repository){
        UserInfo userInfo = repository.findByUserName(userName);
        if(null == userInfo){
            return false;
        }
        return true;
    }



    @Override
    public String login(String account, String password) {
        throw new RuntimeException();
    }

    @Override
    public String register(UserInfo info) {
        throw new RuntimeException();
    }

    @Override
    public boolean checkUserExists(String userName) {
        throw new RuntimeException();
    }

    @Override
    public String login3Rd(HttpServletRequest request) {
        throw new RuntimeException();
    }
}
